package com.itheima.d3_dateTime;

import java.util.Calendar;
import java.util.Date;

public class Test4Calendar {
    public static void main(String[] args) {
        //获取日历对象
        java.util.Calendar calendar = java.util.Calendar.getInstance();
        //获取年份
        int year = calendar.get(java.util.Calendar.YEAR);
        System.out.println("年份："+year);
        //获取月份，注意：月份是从0开始的
        int month = calendar.get(java.util.Calendar.MONTH)+1;
        System.out.println("月份："+month);
        //获取日期
        int dayOfMonth = calendar.get(java.util.Calendar.DAY_OF_MONTH);
        System.out.println("日期："+dayOfMonth);
        //获取小时
        int hourOfDay = calendar.get(java.util.Calendar.HOUR_OF_DAY);
        System.out.println("小时："+hourOfDay);
        //获取分钟
        int minute = calendar.get(java.util.Calendar.MINUTE);
        System.out.println("分钟："+minute);
        //获取秒数
        int second = calendar.get(java.util.Calendar.SECOND);
        System.out.println("秒数："+second);

        System.out.println("---------------------");

        Calendar now = Calendar.getInstance();
        System.out.println("当前时间："+now.getTime());

        int year1 = now.get(Calendar.YEAR);
        System.out.println("年份："+year1);

        int hourOfDay1 = now.get(Calendar.HOUR_OF_DAY);
        System.out.println("小时："+hourOfDay1);

        Date d =now.getTime();
        System.out.println("当前时间："+d);

        long time = now.getTimeInMillis();
        System.out.println("当前时间戳："+time);

        now.set(Calendar.YEAR,2023);
        System.out.println(now);

        now.add(Calendar.MONTH, 1);
        now.add(Calendar.DAY_OF_MONTH, -1);
        System.out.println(now);



    }
}
